package com.niiwoo.civet.trade.service.dubbo.newRefund;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.trade.dto.request.RefundRequestDTO;
import com.niiwoo.civet.trade.dto.response.RefundResponseDTO;
import com.niiwoo.civet.trade.service.local.newRefund.dispatch.RefundDispatchLocalService;
import com.niiwoo.civet.trade.service.newRefund.RefundDispatchDubboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@Service(version = "1.0.0")
public class RefundDispatchDubboServiceImpl implements RefundDispatchDubboService
{
    @Autowired
    protected RefundDispatchLocalService refundDispatchLocalService;

    @Override
    public Long refund(RefundRequestDTO requestDTO)
    {
        try
        {
            log.info("RefundDispatchDubboService->refund param:projectId={},requestDTO={}", requestDTO.getProjectId(),requestDTO);
            Long orderId = refundDispatchLocalService.refund(requestDTO);
            log.info("RefundDispatchDubboService->refund result:projectId={},orderId={}", requestDTO.getProjectId(),orderId);
            return orderId;
        }
        catch (Exception e)
        {
            log.error("RefundDispatchDubboService->refund error:projectId={}",requestDTO.getProjectId(),e);
            throw e;
        }
    }

    @Override
    public RefundResponseDTO refundQuery(Long refundOrderId)
    {
        log.info("RefundDispatchDubboService->refundQuery param:refundOrderId={}",refundOrderId);
        RefundResponseDTO responseDTO = refundDispatchLocalService.refundQuery(refundOrderId);
        log.info("RefundDispatchDubboService->refundQuery result:refundOrderId={},response={}", refundOrderId,responseDTO);
        return responseDTO;
    }

    @Override
    public Long refundOrderQuery(String orgRequestNo) {
        log.info("RefundDispatchDubboService->refundOrderQuery param:orgRequestNo={}",orgRequestNo);
        return refundDispatchLocalService.refundOrderQuery(orgRequestNo);
    }

    @Override
    public RefundResponseDTO refundQueryDetail(Long refundOrderId, Boolean needDetail) {
        log.info("RefundDispatchDubboService->refundQueryDetail param:refundOrderId={},isNeedDetail={}",refundOrderId,needDetail);
        RefundResponseDTO responseDTO = refundDispatchLocalService.refundQuery(refundOrderId,needDetail);
        log.info("RefundDispatchDubboService->refundQueryDetail result:refundOrderId={},response={}", refundOrderId,responseDTO);
        return responseDTO;
    }

    @Override
    public Long substituteRefund(RefundRequestDTO refundRequestDTO)
    {
        try
        {
            log.info("RefundDispatchDubboService->substituteRefund param:projectId={},requestDTO={}", refundRequestDTO.getProjectId(),refundRequestDTO);
            Long orderId = refundDispatchLocalService.substituteRefund(refundRequestDTO);
            log.info("RefundDispatchDubboService->substituteRefund result:projectId={},orderId={}", refundRequestDTO.getProjectId(),orderId);
            return orderId;
        }
        catch (Exception e)
        {
            log.error("RefundDispatchDubboService->substituteRefund error:projectId={}",refundRequestDTO.getProjectId(),e);
            throw e;
        }
    }
}
